<?php
class Model_ticket extends CI_Model{
	protected $_table = "tbl_orthertickets";
	protected $_train  = "tbl_trains";
	protected $_destina = "tbl_destinations";
	public function __construct(){
		parent::__construct();
	}
	public function getdestina($id){
		$this->db->where("fromid",$id);
		$this->db->order_by("desti_id","ASC");
		return $this->db->get($this->_destina)->result_array();
	}
	public function getdest($url){
		$this->db->where("url",$url);
		return $this->db->get($this->_destina)->row_array();
	}
	public function listtrains(){
		$this->db->where("typeid !=",1);
		$this->db->order_by("train_order","ASC");
		return $this->db->get($this->_train)->result_array();
	}
	public function getcheaptickets($destid){
		$this->db->where("desti_id",$destid);
		$this->db->limit(1);
		return $this->db->get($this->_table)->row_array();
	}
	public function gettickets($destid,$startdate){
		$this->db->join($this->_train,$this->_train.".train_id = $this->_table".".trainid");
		 $this->db->where("desti_id",$destid);
		 $this->db->where("ticktype",1);
		 $this->db->where("ticknum >",0);
		 $this->db->where("tickdate",$startdate);
		 return $this->db->get($this->_table)->result_array();
	}
}